package algorithm;

/**
 * 226. 翻转二叉树
 * @author Panbo Guo
 * @date 2021/7/20
 */
public class T00226 {

    public static void main(String[] args) {
        Integer[] arr = new Integer[]{4,2,7,1,3,6,9};
        System.out.println(new Solution().invertTree(TreeUtils.buildTree(arr)));
    }

    static class Solution {
        public TreeNode invertTree(TreeNode root) {
            if (root == null)
                return null;
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
            invertTree(root.left);
            invertTree(root.right);
            return root;
        }
    }
}
